<include file="public/header" title="提货中心" body=""/>
<include file="public/header_nav" title="提货中心" href="javascript:history.back(-1);"/>
<style>
    .get_mp span.disable {
        cursor: default;
        color: #e9e9e9;
    }
    
    .foohi {
	    position: fixed;
	    bottom: 0;
	}
	.orderlistshpop{
		margin-bottom: 2.5rem;
	}
</style>
<if condition="empty($user['user_id'])">
    <!--###用户未登录###-->
    <div class="loginlater">
        <img src="__STATIC__/images/small_car.png"/>
        <span>登录后可同步库存信息</span>
        <a href="{:U('Mobile/User/loagin')}">登录</a>
    </div>
</if>
<form action="{:U('Mobile/user/tihuo')}" id="cart2_form" method="post" >
    <div class="cart_list">
        <!--购物车没有商品-s-->
        <div class="nonenothing" <notempty name="user_kucun">style="display: none"</notempty>>
            <img src="__STATIC__/images/nothing.png"/>
            <p>您还暂无任何商品库存</p>
            <a href="{:U('Mobile/Index/index')}">去逛逛</a>
        </div>
        <!--购物车没有商品-e-->
        <foreach name="user_kucun" item="goods_num" key="goods_id">
            <div class="orderlistshpop p">
                <div class="maleri30">
                    <!--商品列表-s-->
                    <div class="sc_list">
                        <div class="radio fl ">
                            <!--商品勾选按钮-->
                            <span onClick="checkGoods(this)" class="che check_t">
                             <i>
                                 <input name="checkItem[]" type="checkbox" style="display:none;" id="idnum_{$goods_id}" value="{$goods_id}_{$goods_num}" checked="checked">
                             </i>
                             </span>
                        </div>
                        <div class="shopimg fl">
                            <a href="{:U('Mobile/Goods/goodsInfo',array('id'=>$goods_id))}">
                                <!--商品图片-->
                                <img src="{$goods_id|goods_thum_images=200,200}">
                            </a>
                        </div>
                        <div class="deleshow fr">
                            <div class="deletes">
                                <!--商品名-->
                                <span class="similar-product-text fl">
                                    <a href="{:U('Mobile/Goods/goodsInfo',array('id'=>$goods_id))}">{$goodslist[$goods_id][goods_name]}</a>
                                </span>
                            </div>
                            <!--商品属性，规格-->
                            <p class="weight">{$goodslist[$goods_id][spec_key_name]}</p>
                            <p class="weight">库存：{$goods_num}</p>
                            <div class="prices">
                                <p class="sc_pri fl">
                                    <!--商品单价-->
                                    <span></span><span>已支付</span>
                                </p>
                                <!--加减数量-->
                                <div class="plus fr get_mp">
                                    <span class="mp_minous">-</span>
                                    <span class="mp_mp">
                                        <input type="text" id="changeQuantity_{$goods_id}" datenum="{$goods_num}"   dateid="{$goods_id}" value="{$goods_num}" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" class="input-num"/>
                                    </span>
                                    <span class="mp_plus">+</span>
                                </div>
                                <p class="sc_pri fr" style="display: none">库存不足
                                </p>
                            </div>
                        </div>
                    </div>
                    <!--商品列表-e-->
                </div>
            </div>
        </foreach>
        <!--地址信息-s-->
        <div class="ttrebu">
            <img src="__STATIC__/images/tt.png"/>
        </div>
        <notempty name="address">
            <div class="edit_gtfix">
                <a href="{:U('Mobile/User/address_list',array('source'=>'tihuo'))}">
                    <div class="namephone fl">
                        <div class="top">
                            <div class="le fl">{$address.consignee}</div>
                            <div class="lr fl">{$address.mobile}</div>
                        </div>
                        <div class="bot">
                            <i class="dwgp"></i>
                            <span style="padding-bottom:3px;">{$address.address}</span>
                        </div>
                        <input type="hidden" value="{$address.address_id}" id="address_id" name="address_id" /> <!--收货地址id-->
                    </div>
                    <div class="fr youjter">
                        <i class="Mright"></i>
                    </div>                
                </a>
            </div>
        <else />
            <div class="edit_gtfix">
                <a href="{:U('Mobile/User/add_address',array('source'=>'tihuo'))}">
                    <div class="namephone fl">
                        <div class="top" >
                           <div class="lr" style="text-align: center;position: relative;top: .9rem;padding: .3rem;">添加收货地址</div>
                        </div>
                        <div class="bot" style="min-height: .8rem;">
                        	 
                            
                            <i class="dwgp"></i>
                            <span style="padding-bottom:3px;"></span>
                        </div>
                        <input type="hidden" value="{$address.address_id}" id="address_id" name="address_id" /> <!--收货地址id-->
                    </div>
                    <div class="fr youjter">
                        <i class="Mright"></i>
                    </div>                
                </a>
            </div>
        </notempty>
        

        <!--支持配送,发票信息-s-->
        <!-- <div class="information_dr">
            <div class="maleri30">
                <div class="invoice list7">
                    <div class="myorder p">
                        <div class="content30">
                            <a class="takeoutps" href="javascript:void(0)">
                                <div class="order">
                                    <div class="fl">
                                        <span>支持配送</span>
                                    </div>
                                    <div class="fr">
                                        <select name="shipping_code">
                                            <foreach name="shippingList" item="v"  key="k">
                                                <option value="{$v.code}">{$v.name}</option>
                                            </foreach>
                                            <option value="ems">邮政物流</option>
                                            <option value="ziti">自提</option>
                                        </select>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div> -->
        <!--卖家留言-s-->
        <div class="customer-messa">
            <div class="maleri30">
                <p>用户备注（50字）</p>
                <textarea class="tapassa" onkeyup="checkfilltextarea('.tapassa','50')" name="user_note" rows="" cols="" placeholder="选填"></textarea>
                <span class="xianzd"><em id="zero">50</em>/50</span>
            </div>
        </div>
    <!--卖家留言-e-->

        <!--提交栏-s-->
        <notempty name="user_kucun">
            <div class="foohi foohiext">
                <div class="payit ma-to-20 payallb">
                    <div class="fl alllef">
                        <div class="radio fl">
                                <span class="che alltoggle checkFull" onClick="checkGoods(this)">
                                    <i></i>
                                </span>
                            <span class="all">全选</span>
                        </div>
                    </div>
                    <div class="fr">
                        <a href="javascript:void(0);" onclick="cart_submit();">去提货</a>
                    </div>
                </div>
            </div>
            <!--提交栏-e-->
         </notempty>
    </div>
</form>
<script type="text/javascript">
    //点击结算
    function cart_submit() {
        //获取选中的商品个数
        var j = 0;
        $('input[name^="checkItem"]:checked').each(function () {
            j++;
        });
        var address_id=$("#address_id").val();
        if(!address_id){
            layer.open({content: '请先选择收货地址', time: 2});
            return false;
        }
        //选择数大于0
        if (j > 0) {
            //跳转订单页面
            document.getElementById("cart2_form").submit();
        } else {
            layer.open({content: '请选择要提货的商品！', time: 2});
            return false;
        }


    }

    //商品数量加减
    $(function(){
        //减数量
        $('.mp_minous').click(function(){
            if(!$(this).hasClass('disable')){
                var inputs = $(this).siblings('.mp_mp').find('input');
                var val = inputs.val();
                var goods_id=inputs.attr('dateid');
                if(val>0){
                    val--;
                }
                inputs.val(val);
                inputs.attr('value',val);
                $('#idnum_'+goods_id).val(goods_id+'_'+val);
                initDecrement();
            }
        })
        //加数量
        $('.mp_plus').click(function(){
            var inputs = $(this).siblings('.mp_mp').find('input');
            var val = inputs.val();
            var goodsnum = inputs.attr('datenum');
            var goods_id=inputs.attr('dateid');
            val++;
            if(val>goodsnum){
                layer.open({content: '商品数量已超出你的库存数量', time: 2});
                return false;
            }
            inputs.val(val);
            inputs.attr('value',val);
            $('#idnum_'+goods_id).val(goods_id+'_'+val);
            initDecrement();
        })
        $(document).on("blur", '.get_mp input', function (e) {
            var changeQuantityNum = parseInt($(this).val());
            var goodsnum = $(this).attr('datenum');
            var goods_id = $(this).attr('dateid');
            if(changeQuantityNum <= 0){
                layer.open({content: '商品数量必须大于0', time: 2});
                $(this).val($(this).attr('value'));
                return false;
            }else if(changeQuantityNum>goodsnum){
                layer.open({content: '商品数量已超出你的库存数量', time: 2});
                $(this).val($(this).attr('value'));
                return false;
            }else{
                $(this).attr('value', changeQuantityNum);
                $('#idnum_'+goods_id).val(goods_id+'_'+changeQuantityNum);
            }
            initDecrement();
        })
    })
    //勾选商品
    function checkGoods(obj){
        if($(obj).hasClass('check_t')){
            //改变颜色
            $(obj).removeClass('check_t');
            //取消选中
            $(obj).find('input').attr('checked',false);
        }else {
            //改变颜色
            $(obj).addClass('check_t');
            //勾选选中
            $(obj).find('input').attr('checked',true);
        }

        //选中全选多选框
        if($(obj).hasClass('checkFull')){
            if($(obj).hasClass('check_t')){
                $(".che").each(function(i,o){
                    $(this).addClass('check_t');
                    $(this).find('input').attr('checked',true);
                })
            }else{
                $(".che").each(function(i,o){
                    $(this).removeClass('check_t');
                    $(this).find('input').attr('checked',false);
                })
            }
        }
    }
    //更改购买数量对减购买数量按钮的操作
    function initDecrement(){
        $("input[id^='changeQuantity']").each(function(i,o){
            if($(o).val() == 1){
                $(o).parents('.get_mp').find('.mp_minous').addClass('disable');
            }
            if($(o).val() > 1){
                $(o).parents('.get_mp').find('.mp_minous').removeClass('disable');
            }
        })
    }
    //多选框点击事件
    $(function () {
        $(document).on("click", '.che', function (e) {
            checkGoods($(this));
            initCheckBox();
        })
    })

    /**
     * 检测选项框
     */
    function initCheckBox(){
        var checkBoxsFlag = true;
        $("input[name^='checkItem']").each(function(i,o){
            if ($(this).attr("checked") != 'checked') {
                checkBoxsFlag = false;
            }
        })
        if(checkBoxsFlag == false){
            $('.checkFull').removeClass('check_t');
        }else{
            $('.checkFull').addClass('check_t');
        }
    }
</script>
</body>
</html>



